package com.theyeasy.dvmini.controller;

import com.theyeasy.dvmini.dataobject.vo.Vo_msg;
import com.theyeasy.dvmini.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
 

@Controller
@RequestMapping("/project")
public class ProjectsController extends BaseController{
	
    @Autowired
    ProjectService projectService;
    
	@RequestMapping("/projectIndex")
	public ModelAndView projectIndex(){
		ModelAndView mv = new ModelAndView("/project/projectlist");
		return mv;
	}
	
	 
	// 项目列表
    @RequestMapping(value = "/getProjectList")
    @ResponseBody
    public Object getProjectList(Integer page,String keyword) {
        
        return new Vo_msg(0,projectService.getProjectList(page, keyword));
    }
    
    //添加
    @RequestMapping(value = "/addProject")
    @ResponseBody
    public Object addProject(String name,String lng,String lat,Integer templetid) {
        String result=projectService.addProject(name, lng, lat, templetid);
        if(result.equals("ok")){
            return new Vo_msg(0,"添加成功");
        }else{
            return new Vo_msg(-1,result);
        }
    }
	
    //修改
    @RequestMapping(value = "/updateProject")
    @ResponseBody
    public Object updateProject(Integer id,String name,String lng,String lat,Integer templetid) {
        String result=projectService.updateProject(id, name, lng, lat, templetid);
        if(result.equals("ok")){
            return new Vo_msg(0,"添加成功");
        }else{
            return new Vo_msg(-1,result);
        }
        
    }
    
    //删除
    @RequestMapping(value = "/deleteProject")
    @ResponseBody
    public Object deleteProject(Integer id) {
        String result=projectService.deleteProject(id);
        if(result.equals("ok")){
            return new Vo_msg(0,"添加成功");
        }else{
            return new Vo_msg(-1,result);
        }
    }
    
}